﻿using System;

namespace SolarWinds.Extensions
{
    public static class ExceptionExtensions
    {
        public static string GetExceptionString(this Exception exception)
        {
            string errMessage = string.Empty;

            errMessage += exception.Message + Environment.NewLine + exception.StackTrace;

            while (exception.InnerException != null)
            {
                errMessage += GetInnerExceptionString(exception.InnerException);
                exception = exception.InnerException;
            }

            return errMessage;
        }

        public static string GetInnerExceptionString(this Exception exception)
        {
            Exception innerException = exception.InnerException;

            string errMessage = string.Empty;

            errMessage += Environment.NewLine + " InnerException ";
            errMessage += Environment.NewLine + innerException.Message + Environment.NewLine + innerException.StackTrace;

            return errMessage;
        }
    }
}